﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="sooritakanne_ettevotjad_v4", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(SooritakanneEttevotjadV4))]
    public class SooritakanneEttevotjadV4Serializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected ISooritakanneEttevotjadV4 clazz;
        
        public SooritakanneEttevotjadV4Serializer(ISooritakanneEttevotjadV4 clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.Registrikood!=null) {
                Writer.WriteStartElement("registrikood");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Registrikood))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.AsutamiseNumber!=null) {
                Writer.WriteStartElement("asutamise_number");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.AsutamiseNumber))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.KandeSisu!=null) {
                Writer.WriteStartElement("kande_sisu");
                global::Xtee.Core.SerializationMetadata metaKandeSisu = this.GetMetaData(clazz.KandeSisu);
                Writer.WriteTypeAttribute(metaKandeSisu.TypeQualifiedName.Namespace, metaKandeSisu.TypeQualifiedName.Name);
                metaKandeSisu.NewSerializer(clazz.KandeSisu).WriteXml(Writer);
                Writer.WriteEndElement();
            }
            for (int x = 0; ((clazz.Dokumendid != null) 
                        && (x < clazz.Dokumendid.Count)); x = (x + 1)) {
                if (clazz.Dokumendid[x]!=null) {
                    Writer.WriteStartElement("dokumendid");
                    global::Xtee.Core.SerializationMetadata metaDokumendid = this.GetMetaData(clazz.Dokumendid[x]);
                    Writer.WriteTypeAttribute(metaDokumendid.TypeQualifiedName.Namespace, metaDokumendid.TypeQualifiedName.Name);
                    metaDokumendid.NewSerializer(clazz.Dokumendid[x]).WriteXml(Writer);
                    Writer.WriteEndElement();
                }
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="registrikood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>sooritakanne_ettevotjad_v4>registrikood");
                }
                clazz.Registrikood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("registrikood")).Value;
            }
            if (Reader.LocalName=="asutamise_number") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>sooritakanne_ettevotjad_v4>asutamise_number");
                }
                clazz.AsutamiseNumber = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("asutamise_number")).Value;
            }
            if (Reader.LocalName=="kande_sisu") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>sooritakanne_ettevotjad_v4>kande_sisu");
                }
                global::Xtee.Core.SerializationMetadata metaKandeSisu = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.ISooritakanneKandesisuV4>(Reader, "sooritakanne_kandesisu_v4", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                clazz.KandeSisu = metaKandeSisu.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.ISooritakanneKandesisuV4>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("kande_sisu");
                    metaKandeSisu.NewSerializer(clazz.KandeSisu).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="dokumendid") {
                clazz.Dokumendid = new System.Collections.Generic.List<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDokumentTypeV4>();
                for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                            && (Reader.LocalName == "dokumendid")); ) {
                    if ((Reader.IsElementNil() == false)) {
                        global::Xtee.Core.SerializationMetadata metaDokumendid = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDokumentTypeV4>(Reader, "dokumentType_v4", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                        global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDokumentTypeV4 item = metaDokumendid.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDokumentTypeV4>();
                        clazz.Dokumendid.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("dokumendid");
                            metaDokumendid.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    else {
                        clazz.Dokumendid.Add(null);
                        Reader.Skip();
                    }
                }
            }
        }
    }
}
